package com.gitee.wsl.android.notification

//package com.ivy.notifications

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import com.gitee.wsl.ext.K
import com.gitee.wsl.ext.runOnScope

class IvyNotificationChannel(
    val channelId: String,
    val channelName: String,
    val description: String,
    val importance: Int = NotificationManager.IMPORTANCE_DEFAULT,
    val bypassDnd: Boolean = false,
    val lockscreenVisibility:Int = Notification.VISIBILITY_PRIVATE
) {
     fun create(): NotificationChannel {
         // Create the NotificationChannel, but only on API 26+ because
         // the NotificationChannel class is new and not in the support library
         val channel = NotificationChannel(
             channelId,
             channelName,
             importance
         )
         channel.description = description
         //channel.lightColor =  Color.BLUE
         //channel.enableLights(true)
         //channel.enableVibration(true)
         //channel.setBypassDnd(bypassDnd)
         channel.lockscreenVisibility = lockscreenVisibility
         return channel
     }

     companion object{

         val TRANSACTION_REMINDER_CHANNEL by lazy {
             IvyNotificationChannel(
             channelId = "transaction_reminder",
             channelName = "Transaction reminder",
             description = "Reminding you to record your transactions on a daily basis.",
             importance = NotificationManager.IMPORTANCE_HIGH,
             bypassDnd = false
             ).apply {
                 regeditChannel(this)
             }
         }

         val DEFAULT_CHANNEL by lazy {
             IvyNotificationChannel(
                 channelId = "Default channel",
                 channelName = "Default channel",
                 description = "Default channel for normal.",
                 importance = NotificationManager.IMPORTANCE_DEFAULT,
                 bypassDnd = false
             ).apply {
                 regeditChannel(this)
             }
         }

         val DEFAULT_DOWNLOAD_CHANNEL by lazy {
             IvyNotificationChannel(
                 channelId = "Default download channel",
                 channelName = "Default download channel",
                 description = "Default channel for download.",
                 importance = NotificationManager.IMPORTANCE_DEFAULT,
                 bypassDnd = false
             ).apply {
                 regeditChannel(this)
             }
         }

         val DEFAULT_WARN_CHANNEL by lazy {
             IvyNotificationChannel(
                 channelId = "Default warn channel",
                 channelName = "Default warn channel",
                 description = "Default channel for warn.",
                 importance = NotificationManager.IMPORTANCE_DEFAULT,
                 bypassDnd = false
             ).apply {
                 regeditChannel(this)
             }
         }

         val DEFAULT_SERVER_CHANNEL by lazy {
             IvyNotificationChannel(
                 channelId = "Default server channel",
                 channelName = "Default server channel",
                 description = "Default channel for server.",
                 importance = NotificationManager.IMPORTANCE_DEFAULT,
                 bypassDnd = false,
                 lockscreenVisibility=Notification.VISIBILITY_PUBLIC
             ).apply {
                 regeditChannel(this)
             }
         }

         val DEFAULT_ALARM_CHANNEL by lazy {
             IvyNotificationChannel(
                 channelId = "Default alarm channel",
                 channelName = "Default alarm channel",
                 description = "Default channel for alarm.",
                 importance = NotificationManager.IMPORTANCE_DEFAULT,
                 bypassDnd = false,
                 lockscreenVisibility=Notification.VISIBILITY_PUBLIC
             ).apply {
                 regeditChannel(this)
             }
         }


         private fun regeditChannel(channel: IvyNotificationChannel){
             K.runOnScope {
                 notificationManager.createNotificationChannel(channel.create())
             }
         }
     }

}

